<template>
  <div class="header">
    <div class="header-container">
      <div class="logo-section">
        <img src="../assets/logo.jpg" alt="Logo" class="logo" />
        <span class="site-title">河南省体育与艺术用品招标采购平台</span>
      </div>
      <div class="nav-links">
        <router-link to="/" class="nav-link">首页</router-link>
        <router-link to="/info-search" class="nav-link">信息检索</router-link>
        <router-link to="/bid-notice" class="nav-link">数据统计</router-link>
        <router-link to="/win-notice" class="nav-link">关于我们</router-link>
        <router-link to="/help" class="nav-link">帮助中心</router-link>
      </div>


      <div class="user-info" v-if="userPhone">
        <el-dropdown>
          <span class="el-dropdown-link user-link">
            {{ userPhone }}<i class="el-icon-arrow-down"></i>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goToProfile">个人中心</el-dropdown-item>
              <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    <div class="auth-buttons" v-else>
      <div class="user-actions">
        <router-link to="/login" class="user-link">登录</router-link>
        <span class="divider">|</span>
        <router-link to="/register" class="user-link">注册</router-link>
      </div>
    </div>



    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()
const userPhone = computed(() => userStore.phone)

const goToProfile = () => {
  router.push('/profile')
}

const handleLogout = () => {
  userStore.clearUser()
  router.push('/login')
}
</script>

<style scoped>
.header {
  background-color: #495060;
  color: white;
  padding: 10px 0;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}


.el-dropdown-link {
  cursor: pointer;
  outline: none !important;
}

.el-dropdown-link:hover {
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
}


.user-info {
  cursor: pointer;
}

.logo-section {
  display: flex;
  align-items: center;
}

.logo {
  height: 30px;
  margin-right: 10px;
}

.site-title {
  font-size: 16px;
  font-weight: bold;
}

.nav-links {
  display: flex;
}

.nav-link {
  color: white;
  text-decoration: none;
  margin: 0 15px;
  font-size: 14px;
}

.nav-link:hover {
  color: #e6e6e6;
}

.user-actions {
  display: flex;
  align-items: center;
}

.user-link {
  color: white;
  text-decoration: none;
  font-size: 14px;
}

.divider {
  margin: 0 10px;
}
</style>
